//
//  FilePreviewViewController.m
//  MyFramework
//
//  Created by 余洋 on 2018/10/26.
//  Copyright © 2018 余洋. All rights reserved.
//

#import "FilePreviewViewController.h"
#import <QuickLook/QuickLook.h>

@interface FilePreviewViewController ()<QLPreviewControllerDataSource>

@property (strong, nonatomic)QLPreviewController *previewController;
@property (copy, nonatomic)NSURL *fileURL; //文件路径

@end

@implementation FilePreviewViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.previewController = [[QLPreviewController alloc] init];
    self.previewController.dataSource = self;
}

- (IBAction)localAction:(id)sender {
    //获取本地文件路径
    self.fileURL = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"周计划_余洋8.27-8.31.pptx" ofType:nil]];
    [self presentViewController:self.previewController animated:YES completion:nil];
    //刷新界面,如果不刷新的话，不重新走一遍代理方法，返回的url还是上一次的url
    [self.previewController refreshCurrentPreviewItem];
}

#pragma mark - QLPreviewControllerDataSource
-(id<QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index {
    return self.fileURL;
}

- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)previewController{
    return 1;
}
@end
